﻿using Microsoft.AspNetCore.Mvc;
using star_questionnair.Services;

namespace star_questionnair.Controllers;

[Route("correlationAnalysis")]
[ApiController]
public class CorrelationAnalysisController : ControllerBase
{
    private readonly ICorrelationAnalysisService _correlationAnalysisService;

    public CorrelationAnalysisController(ICorrelationAnalysisService correlationAnalysisService)
    {
        _correlationAnalysisService = correlationAnalysisService;
    }
    
    [HttpGet("correlationOqTOq/{questionId1}/{questionId2}/{methodId}")]
    public async Task<IActionResult> CorrelationOqTOq(int questionId1, int questionId2, string methodId)
    {
        try
        {
            var result = await _correlationAnalysisService.CorrelationOqTOqAsync(questionId1, questionId2, methodId);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest($"Error calculating correlation: {ex.Message}");
        }
    }
    
    [HttpGet("correlationOqTO/{questionId}/{optionId}/{methodId}")]
    public async Task<IActionResult> CorrelationOqTO(int questionId, int optionId, string methodId)
    {
        try
        {
            var result = await _correlationAnalysisService.CorrelationOqTOAsync(questionId, optionId, methodId);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest($"Error calculating correlation: {ex.Message}");
        }
    }
    
    [HttpGet("correlationOTO/{optionId1}/{optionId2}/{methodId}")]
    public async Task<IActionResult> CorrelationOTO(int optionId1, int optionId2, string methodId)
    {
        try
        {
            var result = await _correlationAnalysisService.CorrelationOTOAsync(optionId1, optionId2, methodId);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest($"Error calculating correlation: {ex.Message}");
        }
    }
}